<template>
  <div>
    <h1>订单管理</h1>
    <!-- 搜索 -->
    <el-select v-model="select" slot="prepend" placeholder="请选择">
      <el-option label="按商品id查询" value="1"></el-option>
    </el-select>
    <el-input
      style="width: 200px; margin-left: 10px"
      placeholder="请输入内容"
      clearable
      v-model="searchid"
    >
    </el-input>
    <el-button @click="search">搜索</el-button>
    <!-- 渲染 -->
    <template>
      <el-table :data="odlist" style="width: 100%">
        <el-table-column prop="orderNo" label="订单号" width="180">
        </el-table-column>
        <el-table-column prop="receiverName" label="收件人" width="180">
        </el-table-column>
        <el-table-column prop="statusDesc" label="订单状态"> </el-table-column>
        <el-table-column prop="payment" label="订单总价"> </el-table-column>
        <el-table-column prop="createTime" label="创建时间" :formatter="a">
        </el-table-column>
        <el-table-column prop="" label="操作">
          <template slot-scope="scope">
            <el-button @click="cha(scope.row.orderNo)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <!-- 分页器 -->
    <fenyeqi
      :total="fenye.total"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
  </div>
</template>

<script>
import fenyeqi from "../../../components/fenyeqi";
import time from "../../../uilts/time";
import { orderlist, searchid, searchorder } from "../../../http/http";
export default {
  name: "",
  components: {
    fenyeqi,
  },
  props: [],
  data() {
    return {
      odlist: [],
      fenye: {
        total: 1,
        pagesize: 3,
        pagenum: 1,
      },
      select: "",
      searchid: "",
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.getorder();
  },
  methods: {
    //   获取订单数据
    async getorder() {
      const { data: res } = await orderlist(this.fenye);
      console.log(res);
      this.odlist = res.data.list;
      this.fenye.total = res.data.total;
    },
    // 时间转换
    a(row, column, cellValue, index) {
      let b = time(row.createTime);
      return b;
    },
    handleSizeChange(size) {
      console.log(size);
      this.fenye.pagesize = size;
      this.getorder();
    },
    handleCurrentChange(page) {
      console.log(page);
      this.fenye.pagenum = page;
      this.getorder();
    },
    // 查询订单
    async search() {
      const { data: res } = await searchorder(this.searchid);
      console.log(res);
      this.odlist = res.data.list;
      this.fenye.total = res.data.total;
    },
    cha(id) {
      console.log(id);
      this.$router.push({
        name: "orderxq",
        params: {
          id: id,
        },
      });
    },
  },
};
</script>

<style lang='scss' scoped>
</style>
